import request from '@/utils/request'
import type { CartItem } from "@/types/cart";

export const addToCart = (productId: number, quantity: number) => {
  return request({
    url: '/shoppingCart/add',
    method: 'post',
    data: {
      productId,
      quantity,
    }
  })
}

// 获取购物车列表
export const getCartList = () => {
  return request({
    url: '/shoppingCart/queryByUserId',
    method: 'get'
  })
}

// 删除购物车商品
export const deleteCartItem = (data: { id: number }) => {
  return request({
    url: '/shoppingCart/deleteById',
    method: 'post',
    data
  })
}

// 清空购物车
export const clearCart = () => {
  return request({
    url: '/shoppingCart/clear',
    method: 'delete'
  })
}

export const updateCartQuantity = (shoppingCartId: number, quantity: number) => {
  return request({
    url: '/shoppingCart/update',
    method: 'put',
    data: {
      shoppingCartId,
      quantity,
    }
  })
}

export const removeFromCart = (shoppingCartId: number) => {
  return request({
    url: `/shoppingCart/delete/${shoppingCartId}`,
    method: 'delete'
  })
} 